/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rie06.openvoip.client;

import com.rie06.openvoip.sound.AudioRecording;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

/**
 *
 * @author clement
 */
public class ConversationRecorder extends AudioRecording {

    private Conversation conversation;

    public ConversationRecorder(Conversation conversation) {
        super();
        this.conversation = conversation;
    }

    @Override
    
    
       /** 
         * Envoie le son
         * 
         */
    public void sendSound(int id, byte[] payload_voice) {

        byte[] conversationID = new byte[36];
        byte[] userID = new byte[36];
        byte[] total = new byte[72 + this.bufSize];

        conversationID = conversation.getUuid().toString().getBytes();
        userID = conversation.getClient().getServer().getServerConfig().getId().toString().getBytes();

        int j = 0, k = 0, l = 0;
        for (int i = 0; i < total.length; i++) {
            if (i < 36) {
                total[i] = conversationID[j++];
            } else if (i < 72) {
                total[i] = userID[k++];
            } else {
                total[i] = payload_voice[l++];
            }
        }

        HashMap m = (HashMap) conversation.getContactListCall();
        for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
            Map.Entry<UUID, Contact> entry = (Map.Entry<UUID, Contact>) it.next();

            UUID uuid = entry.getKey();
            Contact contact = entry.getValue();

            //send Buffer
            conversation.getClient().sendUDP(total, conversation.getSocket(), contact);

        }

    }
}
